//
//  AIFUploadAccountLoginTimeManager.m
//  PywSdk
//
//  Created by Ampaw on 2017/6/20.
//  Copyright © 2017年 Jade. All rights reserved.
//

#import "AIFUploadAccountLoginTimeManager.h"

@implementation AIFUploadAccountLoginTimeManager

NSString *const UploadAccountLoginTime_GameId = @"gameid";
NSString *const UploadAccountLoginTime_Sign = @"sign";
NSString *const UploadAccountLoginTime_Tid = @"tid";
NSString *const UploadAccountLoginTime_Token = @"token";
NSString *const UploadAccountLoginTime_parameterList = @"parameterList";

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.child = self;
        self.paramSource = self;
        self.validate = self;
    }
    return self;
}


#pragma mark - ETAPIManager
- (NSString *)methodName{
    return @"";
}

- (ETAPIManagerRequestType)requestType{
    return ETAPIManagerRequestTypePost;
}


- (NSString *)seriviceType{
    return kAIFServiceUploadLoginTime;
}


#pragma mark - ETAPIManagerParamSourceDelegate
- (NSDictionary *)paramsForApi:(ETApiBaseManager *)manager{
    
    NSString * tid = [PywAppInfo sharedAppInfo].tid;
    NSString * gameid = [PywAppInfo sharedAppInfo].gameId;
    NSString * account = [PywPlatformMain sharedPlatformMain].account;
    NSString * apiSecret2 = [AppUtil getApiSecret2:tid apiSecret:[PywAppInfo sharedAppInfo].apisecret];
    NSString * sign = [PywCipherUtils md5:[NSString stringWithFormat:@"%@%@%@",gameid,account,apiSecret2]];
    
    NSString * token = [PywPlatformMain sharedPlatformMain].token;
    NSString *parameterListJsonStr = [self jsonStringWithArray:self.parameterList];
    
    MutableDictionary *param = [[MutableDictionary alloc] init];
    [param setObject:gameid forKey:UploadAccountLoginTime_GameId];
    [param setObject:tid forKey:UploadAccountLoginTime_Tid];
    [param setObject:sign forKey:UploadAccountLoginTime_Sign];
    [param setObject:token forKey:UploadAccountLoginTime_Token];
    [param setObject:parameterListJsonStr forKey:UploadAccountLoginTime_parameterList];
    return param;
}

// 将Array转换为Json串
- (NSString *)jsonStringWithArray:(NSMutableArray *)array
{
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.parameterList
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    if (!jsonData) {
        PLog(@"jsonStringWithPrettyPrint: error: %@", error.localizedDescription);
        return @"[]";
    } else {
        return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
}


#pragma mark - ETAPIManagerValidator
- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return YES;
}

- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    return YES;
}

@end
